<?php
class Service_IndexController extends Zendme_Controller_Action
{
	//Mang tham so nhan duoc o moi Action
	protected $_arrParam;
	
	//Duong dan cua Controller
	protected $_currentController;
	
	//Duong dan cua Action chinh
	protected $_actionMain;
	
	protected $_namespace;
	
	protected $_paginator = array(
									'itemCountPerPage' => 8,
									'pageRange' => 4,
								  ); 
	
	public function init()
	{	
		//Mang tham so nhan duoc o moi Action
		$this->_arrParam = $this->_request->getParams();
		
		//Duong dan cua Controller
		$this->_currentController = '/' . $this->_arrParam['module'] 
									 . '/' . $this->_arrParam['controller'];		
		//Duong dan cua Action chinh		
		$this->_actionMain = '/' . $this->_arrParam['module'] 
							 . '/' . $this->_arrParam['controller']	. '/index';	
							 
		$this->_paginator['currentPage'] = $this->_request->getParam('page',1);
		$this->_arrParam['paginator'] = $this->_paginator;					 
		
		//Luu cac du lieu filter vao SESSION
		$this->_namespace = $this->_arrParam['module'] . '-' . $this->_arrParam['controller'];
		$ssFilter = new Zend_Session_Namespace($this->_namespace);
		//$ssFilter->unsetAll();
		if(empty($ssFilter->col)){
			$ssFilter->keywords 	= '';
			$ssFilter->col 			= 'c.id';
			$ssFilter->order 		= 'DESC';
			$ssFilter->lang 		= '';
		}
		$this->_arrParam['ssFilter']['keywords'] 	= $ssFilter->keywords;
		$this->_arrParam['ssFilter']['col'] 		= $ssFilter->col;
		$this->_arrParam['ssFilter']['order'] 		= $ssFilter->order;	
		$this->_arrParam['ssFilter']['lang'] 		= $this->_arrParam['lang'];
		
		$info = new Zendme_System_Info();
		$language = $info->getLanguage('admin');
		if(empty($language)){
			$language = 'vi';
		}
		$translate = array(
							'adapter' => 'tmx',
							'content' => LANG_PATH . '/' . $language . '/admin/menu.tmx',
							'locale' => $language,
							);
		$translate = new Zend_Translate($translate);
		Zend_Registry::set('Zend_Translate', $translate);
		
		//Truyen ra view
		$this->view->arrParam = $this->_arrParam;
		$this->view->currentController = $this->_currentController;
		$this->view->actionMain = $this->_actionMain;		
		
		Zend_Layout::getMvcInstance()->assign('bg', 'bag-image-page');
		Zend_Layout::getMvcInstance()->assign('current', 'service');
		
		$template_path = TEMPLATE_PATH . "/front/system1";
		$this->loadTemplate($template_path,'template.ini','template');
		
	}
	
	public function indexAction()
	{	
		$mdlItem=new Zendme_Models_ServiceItem();
		$items=$mdlItem->listItem($this->_arrParam,array('task'=>'public-index'));	
		$this->view->items=$items;
		
		$totalItem  = $mdlItem->countItem($this->_arrParam,array('task'=>'public-index'));	
		
		$paginator = new Zendme_Paginator();
		$this->view->panigator = $paginator->createPaginator($totalItem,$this->_paginator);
		//$this->view->total = $mdlItem->countItem($this->_arrParam,array('task'=>'public-category'));
		
		$this->view->headTitle('Dịch vụ');
		$this->view->headMeta()->appendName('description', ''); 
		$this->view->headMeta()->appendName('keywords', ''); 
	}
	
	public function categoryAction()
	{
		$mdlCatalog=new Zendme_Models_CategoryService();
		$category=$mdlCatalog->getItem($this->_arrParam,array('task'=>'public-detail'));
		$this->view->category=$category;
		//var_dump($category); die();
		
		$mdlServiceItem =new Zendme_Models_ServiceItem();
		$items=$mdlServiceItem->listItem($this->_arrParam,array('task'=>'public-category'));
		$this->view->items=$items;
		
		$this->view->headTitle($category['name']);
		
		if(!empty($category['meta_description']))
		$this->view->headMeta()->appendName('description', $category['meta_description']); 
		if(!empty($category['meta_keyword']))
		$this->view->headMeta()->appendName('keywords', $category['meta_keyword']); 
	}
	
	public function detailAction()
	{
		$mdlService=new Zendme_Models_ServiceItem();
		$item=$mdlService->getItem($this->_arrParam,array('task'=>'public-detail'));
		$this->view->item=$item;
		
		$this->view->headTitle($item['name']);
		if(!empty($item['meta_description']))
		$this->view->headMeta()->appendName('description', $item['meta_description']); 
		if(!empty($item['meta_keyword']))
		$this->view->headMeta()->appendName('keywords', $item['meta_keyword']); 
	}
}